$(function () {

    //变量抽取
    var attendance_dataGrid = $("#attendance_dataGrid");
    var attendance_dialog = $("#attendance_dialog");
    var attendance_form = $("#attendance_form");

    attendance_dataGrid.datagrid({
        fitColumns: true,//列自适应
        url: "/attendance/query",
        fit: true,
        columns: [[
            {field: 'date', title: '日期', width: 100},
            {field: 'emp', title: '员工姓名', width: 100,formatter:function (value, row, index) {
                    return value? value.realname :"";
                }},
            {field: 'clockIn', title: '上班时间', width: 100},
            {field: 'clock0ut', title: '下班时间', width: 100},
            {field: 'state', title: '考勤状态', width: 100,formatter:function (value,row,index) {
                    return value == 0? "<font color='red'>缺勤</font>":"<font color='green'>正常</font>";
                }},
        ]],
        pagination: true,//分页
        toolbar: '#tb',
        rownumbers: true,//行号
        singleSelect: true,//只允许选择一行
    });

    attendance_dialog.dialog({
        width: 400,
        height: 400,
        buttons: "#btns",
        closed: true,
        onClose: function () {
            attendance_form.form("clear");
        },
        resizeable:true
    });

    //方法抽成对象统一管理
    var methodObj = {
        searchForm: function () {
            var keyword = $("input[name='keyword']").val();
            var startDate = $("input[name='startDate']").val();
            var endDate = $("input[name='endDate']").val();
            attendance_dataGrid.datagrid('load', {
                keyword: keyword,
                startDate:startDate,
                endDate:endDate
            });
        },
        reload: function () {
            attendance_dataGrid.datagrid("load",{});
            $(".search").textbox("clear");
        }
    };

    //按钮统一绑定事件
    $("a[data-cmd]").click(function () {
        var cmd = $(this).data("cmd");
        methodObj[cmd]();
    });
});
